<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div style="padding: 5px;">
	<form class="form-horizontal">
		<div class="form-group">
			<div class="row">
				<label for="commnetedContent" class="col-sm-1 control-label">主题:</label>
				<div class="col-sm-2">
					<input type="text" class="form-control" id="theme">
				</div>
				<div class="col-sm-2">
					<button type="button" class="btn btn-primary no-border btn-sm" id="searchBtn">
						<span class="fa fa-search"></span>查询
					</button>
				</div>
			</div>
		</div>
	</form>
	<div id="forumFansPostGrid" class="forumFansPostGrid"></div>
</div>
<script>
	$(function() {
		var cols = [{
			title : '主题',
			name : 'theme',
			width : '150px'
		}, {
			title : '内容',
			name : 'content',
			width : '150px'
		}, {
			title : '发帖人',
			name : 'authUserName',
			width : '150px'
		}, {
			title : '发帖时间',
			name : 'postDateStr',
			width : '150px'
		}];
		var buttons = [{
			content : '<button class="btn btn-info no-border btn-sm" type="button"><span class="fa fa-search"></span>查看</button>',
			action : 'view'
		}, {
			content : '<button class="btn btn-primary no-border btn-sm" type="button"><span class="fa fa-plus"></span>&nbsp;新增</button>',
			action : 'add'
		}, {
			content : '<button class="btn btn-success no-border btn-sm" type="button"><span class="fa fa-pencil-square-o"></span>&nbsp;修改</button>',
			action : 'modify'
		}, {
			content : '<button class="btn btn-danger no-border btn-sm" type="button"><span class="fa fa-trash-o"></span>&nbsp;删除</button>',
			action : 'delete'
		}];
		$('#forumFansPostGrid').grid({
			identity : 'id',
			columns : cols,
			buttons : buttons,
			url : contextPath + '/forumFansPost/query'
		}).on({
			'view' : function(event, data) {
				var indexs = data.data;
				var $this = $(this);
				if (indexs.length == 0) {
					$this.message({
						type : 'warning',
						content : '请选择一条记录进行修改'
					})
					return;
				}
				if (indexs.length > 1) {
					$this.message({
						type : 'warning',
						content : '只能选择一条记录进行修改'
					})
					return;
				}
				seajs.use('forumFansPost', function(forumFansPost) {
					forumFansPost.view(indexs[0], $this);
				});
			},
			'add' : function() {
				seajs.use('forumFansPost', function(forumFansPost) {
					forumFansPost.add();
				});
			},
			'modify' : function(event, data) {
				var indexs = data.data;
				var $this = $(this);
				if (indexs.length == 0) {
					$this.message({
						type : 'warning',
						content : '请选择一条记录进行修改'
					})
					return;
				}
				if (indexs.length > 1) {
					$this.message({
						type : 'warning',
						content : '只能选择一条记录进行修改'
					})
					return;
				}
				seajs.use('forumFansPost', function(forumFansPost) {
					forumFansPost.modify(indexs[0], $this);
				});
			},
			'delete' : function(event, data) {
				var indexs = data.data;
				var $this = $(this)
				if (indexs.length == 0) {
					$this.message({
						type : 'warning',
						content : '请选择要删除的记录'
					})
					return;
				}
				$this.confirm({
					content : '确定要删除所选记录吗?',
					callBack : function() {
						seajs.use('forumFansPost', function(forumFansPost) {
							forumFansPost.remove(indexs, $this);
						});
					}
				});
			}
		});
		$('#searchBtn').on('click', function() {
			seajs.use('util', function(util) {
				$('#forumFansPostGrid').getGrid().search(util.getFormData(pageContents.find('form')));
			});
		});
	}); 
</script>
